package com.stockz.core.dao.hsql;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.stockz.core.dao.ConfigurationDao;
import com.stockz.core.model.Configuration;

@Repository
@Transactional
public class ConfigurationDaoImpl implements ConfigurationDao {

	private EntityManager entityManager;
	
	@PersistenceContext
	public void setEntityManager(EntityManager entityManager) {
	    this.entityManager = entityManager;
	}
	
	@SuppressWarnings("unchecked")
	@Transactional(propagation=Propagation.MANDATORY, readOnly=true)
	public List<Configuration> getAllConfiguration(){
		return entityManager.createQuery("select c from Configuration c").getResultList();
	}
	
	@Transactional(propagation=Propagation.MANDATORY)
	public void remove(Configuration configuration){
		if(configuration != null){
			entityManager.remove(configuration);
		}
	}
	
	@Transactional(propagation=Propagation.MANDATORY)
	public void persist(Configuration configuration){
		if(configuration != null){
			entityManager.persist(configuration);
		}
	}
	
	@Transactional(propagation=Propagation.MANDATORY)
	public void merge(Configuration configuration){
		if(configuration != null){
			entityManager.merge(configuration);
		}
	}

}
